package com.jason.rabbitmq.listener;

import com.google.gson.Gson;
import com.jason.rabbitmq.entity.Order;
import com.jason.rabbitmq.util.OrderUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class DeadPayListener {

    @RabbitListener(queues = "dead.pay")
    public void receiveMessage(String message) {
        System.out.println("收到超时订单消息:" + message);
        Gson gson = new Gson();
        Order order = gson.fromJson(message, Order.class);
        //比较订单是否已经支付
        Order payOrder = OrderUtil.getOrder(order.getId());
        if (payOrder.getStatus() == Order.WAIT_PAY) {
            payOrder.setStatus(Order.OVERTIME);
            payOrder.setStatusDesc("支付超时");
        }
    }
}
